def max(xs:List[Int])={
    var max=0
    for(i<-0 to xs.length-1) max=Math.max(xs(i),max)
    max
}
def transpose(xss:Array[Array[Int]],x:Int,y:Int) = {
    var yss=Array[Array[Int]](x,y)
    for(i<-0 to x,j<-0 to y) {
        yss(j)(i)=xss(i)(j)
    }
   yss
}
def primeFilter(x:Int):List[Int]= List.range(2,x+1) filter ((y) => isPrime(y)) 

def isPrime(x:Int)=List.range(2,x) forall ((y) => x%y!=0)

def maxPower(n:Int,y:Int):Int= {
    if((n<y)|| (n%y!=0)) 0
    else maxPower(n/y,y) + 1
}

def power(n:Int,xs:List[Int])=  xs map((y)=> maxPower(n,y))
   

def lowestCommonMultiple(xs:List[Int]):Long = {
    if(xs==Nil) 0l
    else {
        var j=1l
        var maxOfInput=max(xs)
        var primeList=primeFilter(maxOfInput)
        var xss=List[List[Int]]()
        var highPrimes=new Array[Int](primeList.length)
        xss=xs map ((y) => power(y,primeList))
        var highPrimeHelp=List[Int]()
        for(aj <-0 to highPrimes.length-1) {
            highPrimeHelp=xss map ((y)=>y(aj))
            highPrimes(aj)=max(highPrimeHelp)
        }    
        for(l <- 0 to primeList.length-1) {
            j=j*(Math.pow(primeList(l).toDouble,highPrimes(l).toDouble)).toLong
        }
        j
    }
}

test("This is the LCM") {
    lowestCommonMultiple(List()) should equal (0l)  

    lowestCommonMultiple(List(1,2,3,4,5,6,7)) should equal (420l) 
}
println(lowestCommonMultiple(List(1,2,3,3)))


        